//
//  EditPicViewController.m
//  嘀嘀拍
//
//  Created by 陈一航 on 16/3/4.
//  Copyright © 2016年 wangjia_01. All rights reserved.
//

#import "EditPicViewController.h"
#import "GPUImage.h"


@interface EditPicViewController ()
@property (nonatomic,strong)GPUImageView *gpuView;

@property (nonatomic,strong)GPUImagePicture *gpuPic;

@property (weak, nonatomic) IBOutlet UIImageView *imageSource;
@property (weak, nonatomic) IBOutlet UIButton *musicBtn;

@end

@implementation EditPicViewController
- (IBAction)clickChangeImageFilter:(id)sender {
    
    UIButton *button=sender;
    switch (button.tag-5000) {
        case 0:
              DLog(@"%@",button.titleLabel.text);
                   break;
        case 1:
              DLog(@"%@",button.titleLabel.text);
            break;
        case 2:
            {
            GPUImageClosingFilter *filter = [[GPUImageClosingFilter alloc] init];
              
                
            [filter forceProcessingAtSize:_imageSource.image.size];
            GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:_imageSource.image];
            [pic addTarget:filter];
            [pic processImage];
            [filter useNextFrameForImageCapture];
            _imageSource.image= [filter imageFromCurrentFramebuffer];
            
            }

              DLog(@"%@",button.titleLabel.text);
            break;
        case 3:
              DLog(@"%@",button.titleLabel.text);
        {
            GPUImagePixellateFilter *filter = [[ GPUImagePixellateFilter alloc] init];
            
            
            [filter forceProcessingAtSize:_imageSource.image.size];
            GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:_imageSource.image];
            [pic addTarget:filter];
            [pic processImage];
            [filter useNextFrameForImageCapture];
            _imageSource.image= [filter imageFromCurrentFramebuffer];
            
        }

            
            break;
        case 4:
            
        {
            GPUImageGaussianBlurFilter *filter = [[ GPUImageGaussianBlurFilter alloc] init];
            
            
            [filter forceProcessingAtSize:_imageSource.image.size];
            GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:_imageSource.image];
            [pic addTarget:filter];
            [pic processImage];
            [filter useNextFrameForImageCapture];
            _imageSource.image= [filter imageFromCurrentFramebuffer];
            
              DLog(@"%@",button.titleLabel.text);
        }
            break;
        case 5:
        {
            GPUImageTiltShiftFilter *filter = [[ GPUImageTiltShiftFilter alloc] init];
            
            
            [filter forceProcessingAtSize:_imageSource.image.size];
            GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:_imageSource.image];
            [pic addTarget:filter];
            [pic processImage];
            [filter useNextFrameForImageCapture];
            _imageSource.image= [filter imageFromCurrentFramebuffer];
            
            DLog(@"%@",button.titleLabel.text);
        }

            break;
        case 6:
        {
            GPUImageToonFilter *filter = [[ GPUImageToonFilter alloc] init];
            
            
            [filter forceProcessingAtSize:_imageSource.image.size];
            GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:_imageSource.image];
            [pic addTarget:filter];
            [pic processImage];
            [filter useNextFrameForImageCapture];
            _imageSource.image= [filter imageFromCurrentFramebuffer];
            
            DLog(@"%@",button.titleLabel.text);
        }

            break;
        case 7:
        {
            GPUImageSepiaFilter *filter = [[ GPUImageSepiaFilter alloc] init];
            
            
            [filter forceProcessingAtSize:_imageSource.image.size];
            GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:_imageSource.image];
            [pic addTarget:filter];
            [pic processImage];
            [filter useNextFrameForImageCapture];
            _imageSource.image= [filter imageFromCurrentFramebuffer];
            
            DLog(@"%@",button.titleLabel.text);
        }

            break;
        case 8:
        {
            GPUImageSwirlFilter *filter = [[GPUImageSwirlFilter alloc] init];
            
            
            [filter forceProcessingAtSize:_imageSource.image.size];
            GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:_imageSource.image];
            [pic addTarget:filter];
            [pic processImage];
            [filter useNextFrameForImageCapture];
            _imageSource.image= [filter imageFromCurrentFramebuffer];
            
            DLog(@"%@",button.titleLabel.text);
        }

            
           // _imageSource.image=[UIImage imageNamed:@"速度与激情1点击播放后"];
            
            break;
        case 9:
            DLog(@"%@",button.titleLabel.text);
            
            _imageSource.image=[UIImage imageNamed:@"速度与激情1点击播放后"];
            
            break;
            
            
        default:
            break;
    }
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _musicBtn.layer.borderColor=[UIColor groupTableViewBackgroundColor].CGColor;
    _musicBtn.layer.borderWidth=1;
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
